package com.example.demo.controller;

import com.example.demo.entity.CourseVideo;
import com.example.demo.service.CourseVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/courseVideos")
@CrossOrigin
public class CourseVideoController {

    @Autowired
    private CourseVideoService courseVideoService;

    // 新增课程视频
    @PostMapping
    public int insertCourseVideo(@RequestBody CourseVideo courseVideo) {
        return courseVideoService.insertCourseVideo(courseVideo);
    }

    // 删除课程视频
    @DeleteMapping("/{id}")
    public int deleteCourseVideoById(@PathVariable int id) {
        return courseVideoService.deleteCourseVideoById(id);
    }

    // 修改课程视频
    @PutMapping
    public int updateCourseVideo(@RequestBody CourseVideo courseVideo) {
        return courseVideoService.updateCourseVideo(courseVideo);
    }

    // 查询课程视频
    @GetMapping("/{id}")
    public CourseVideo selectCourseVideoById(@PathVariable int id) {
        return courseVideoService.selectCourseVideoById(id);
    }

    // 查询所有课程视频
    @GetMapping
    public List<CourseVideo> selectAllCourseVideos() {
        return courseVideoService.selectAllCourseVideos();
    }

    // 联合查询课程及其视频信息
    @GetMapping("/course/{courseId}")
    public List<CourseVideo> selectCourseVideosByCourseId(@PathVariable int courseId) {
        return courseVideoService.selectCourseVideosByCourseId(courseId);
    }
}
